package com.kevin.spring.jdbc;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Repository
public class UserDaoImp implements UserDao {

	private SimpleJdbcTemplate simpleJdbcTemplate;

	@Autowired
	public void setDataSource(DataSource dataSource) {
		this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
	}

	@Override
	public void save(User user) {

		String sql = "insert into user(name,age) value(?,?)";
		this.simpleJdbcTemplate.update(sql, user.getName(), user.getAge());
	}

	@Override
	public void update(User user) {
		// TODO Auto-generated method stub

	}

	@Override
	public User getUser(Integer userid) {

		return this.simpleJdbcTemplate.queryForObject(
				"select * from user where id=?", new UserRowMapper(), userid);
	}

	@Override
	public List<User> getUsers() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void delete(Integer userid) {
		// TODO Auto-generated method stub

	}
}
